package com.example.cm_network

import retrofit2.http.GET
import retrofit2.http.Path
import retrofit2.http.Query

/**
 * 音乐服务器API接口定义
 *  符合RESTful API
 */
interface ApiService {
    
    /**
     * 获取首页推荐数据
     */
    @GET("home/recommend")
    suspend fun getHomeRecommend(): HomeResponse
    
    /**
     * 获取轮播图数据
     */
    @GET("banner")
    suspend fun getBanners(): BannerResponse
    
    /**
     * 获取歌单详情
     */
    @GET("playlist/detail")
    suspend fun getPlaylistDetail(@Query("id") id: String): PlaylistDetailResponse
    
    /**
     * 获取歌曲详情
     */
    @GET("song/detail")
    suspend fun getSongDetail(@Query("id") id: String): SongDetailResponse
    
    /**
     * 获取推荐艺人
     */
    @GET("artist/recommend")
    suspend fun getRecommendArtists(): ArtistResponse
    
    /**
     * 搜索音乐
     */
    @GET("search")
    suspend fun search(
        @Query("keywords") keywords: String,
        @Query("type") type: Int = 1,
        @Query("limit") limit: Int = 30,
        @Query("offset") offset: Int = 0
    ): SearchResponse
}

/**
 * API响应数据类
 */
data class BaseResponse(
    val code: Int,
    val message: String?
)

data class HomeResponse(
    val code: Int,
    val data: HomeData
)

data class BannerResponse(
    val code: Int,
    val banners: List<BannerData>
)

data class PlaylistDetailResponse(
    val code: Int,
    val playlist: PlaylistData
)

data class SongDetailResponse(
    val code: Int,
    val songs: List<SongData>
)

data class ArtistResponse(
    val code: Int,
    val artists: List<ArtistData>
)

data class SearchResponse(
    val code: Int,
    val result: SearchResult
)

// 下面定义数据实体类
data class HomeData(
    val blocks: List<BlockData>
)

data class BlockData(
    val blockCode: String,
    val showType: String,
    val title: String,
    val items: List<Any> // 实际项目中应该定义具体类型
)

data class BannerData(
    val imageUrl: String,
    val targetId: String,
    val targetType: Int,
    val titleColor: String,
    val typeTitle: String,
    val url: String
)

data class PlaylistData(
    val id: String,
    val name: String,
    val coverImgUrl: String,
    val description: String,
    val playCount: Long,
    val tracks: List<SongData>
)

data class SongData(
    val id: String,
    val name: String,
    val artists: List<ArtistData>,
    val album: AlbumData,
    val duration: Long
)

data class ArtistData(
    val id: String,
    val name: String,
    val picUrl: String,
    val alias: List<String>
)

data class AlbumData(
    val id: String,
    val name: String,
    val picUrl: String
)

data class SearchResult(
    val songs: List<SongData>?,
    val artists: List<ArtistData>?,
    val albums: List<AlbumData>?,
    val playlists: List<PlaylistData>?
) 